package com.zjj.day2.test3;

/**
 * @author zhoujunjie
 * @desc TODO
 * @date 2025/4/18
 */
public class Person {
    private String name;
    private int age;
    private boolean gender;
    private Person partner;

    public void setpartner(Person p) {
        this.partner = p;
    }

    public Person(String name, int age, boolean gender, Person partner) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.partner =partner ;
    }
    public void marry(Person p){
        if (this.gender==p.gender){
            System.out.println("同性不能结婚");
        }
        else if(((this.gender&&this.age<24)||(!p.gender&&p.age<22))||((!this.gender&&this.age<22)||(p.gender&&p.age<24))){
            System.out.println("年龄不足不能结婚");
        }
        else if (p.partner!=null||this.partner!=null){
            System.out.println("某一方已婚，不能结婚");
        }
        else {
            this.setpartner(p);
            p.setpartner(this);
            System.out.println("祝贺"+this.name+"与"+p.name+"喜结连理");
        }
    }
}

